﻿/*----------------------------------------------------------------
  //Copyright (C) 2012 赵国伟
  //文件功能描述：员工管理Ajax请求服务端处理程序。
  //创建人：赵国伟
  //生成时间：2012/03/17 16:15:00
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Shopping.Common;
using Shopping.Model;
using Shopping.BLL;

public partial class Manage_AS_EmployeesCommon : BaseManagePage
{
    private readonly EmployeesManage bllEmployee = new EmployeesManage();

    protected void Page_Load(object sender, EventArgs e)
    {
        string action = Request.QueryString["Action"] as string;
        switch (action)
        {
            case "SaveEmployee":   //保存员工信息； by 赵国伟 2012-03-17
                SaveEmployee();
                break;
            case "GetEmployee":  //获取一条员工信息；by 赵国伟 2012-03-17
                GetEmployee();
                break;
            case "DeleteEmployee":  //删除一条员工信息； by 赵国伟 2012-03-17
                DeleteEmployee();
                break;
        }
        Response.End();
    }

    #region "保存员工信息 by 赵国伟 2012-03-17"
    /// <summary>
    /// 保存员工信息
    /// </summary>
    private void SaveEmployee()
    {
        string jsonOfData = Request.Form["jsonData"] + "";
        string roleIds = Request.Form["roleIds"] + ""; //角色；
        ReturnValue ret = new ReturnValue();
        Employees employeeInfo = null;
        try
        {
            employeeInfo = JSONHelper.JsonStringToObject<Employees>(jsonOfData);
        }
        catch (Exception e)
        {
            ret.Message = "Json反序列化失败 原因:" + e.Message;
            Response.Write(ret.ToJsonString());
            return;
        }
        ret = bllEmployee.Save(employeeInfo, roleIds);
        Response.Write(ret.ToJsonString());
    }
    #endregion

    #region "获取一条指定的员工信息  by 赵国伟 2012-03-17"
    /// <summary>
    /// 获取一条指定的员工信息
    /// </summary>
    private void GetEmployee()
    {
        int EmployeeID = Utility.Cast2int(Request.QueryString["EmployeeID"]);
        EmployeeInfo employeeInfo = bllEmployee.GetEmployee(EmployeeID);
        if (employeeInfo != null)
            Response.Write(JSONHelper.ObjectToJson<EmployeeInfo>(employeeInfo));
    }
    #endregion

    #region "删除一条指定的员工信息； by 赵国伟 2012-03-17"
    /// <summary>
    /// 删除一条指定的员工信息；
    /// </summary>
    private void DeleteEmployee()
    {
        int EmployeeId = Utility.Cast2int(Request.QueryString["EmployeeId"]);
        Response.Write(bllEmployee.UpdateStatus(EmployeeId, Status.已删除).ToJsonString());
    }
    #endregion












}